﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppGene.DataModel
{
    public class LogicalIndex
    {
        /// <summary>
        /// Creates an index instance.
        /// </summary>
        private LogicalIndex()
        {
            IsPrimaryKey = false;
            IsClustered = true;
            IsUnique = true;
        }

        /// <summary>
        /// Creates an index instance.
        /// </summary>
        /// <param name="column">The column name of index.</param>
        internal LogicalIndex(LogicalColumn column)
            : this(new LogicalColumn[] { column })
        { }

        /// <summary>
        /// Creates an index instance.
        /// </summary>
        /// <param name="column">The column of index.</param>
        /// <param name="column2">The second column of index.</param>
        internal LogicalIndex(LogicalColumn column, LogicalColumn column2)
            : this(new LogicalColumn[] { column, column2 })
        { }

        /// <summary>
        /// Creates a index instance.
        /// </summary>
        /// <param name="columns">The columns for the index.</param>
        internal LogicalIndex(LogicalColumn[] columns)
            : this()
        {
            this.Columns = new ReadOnlyCollection<LogicalColumn>(columns);
        }

        /// <summary>
        /// Gets the column collection for the index.
        /// </summary>
        public ReadOnlyCollection<LogicalColumn> Columns { get; private set; }

        /// <summary>
        /// Gets or Sets the index table.
        /// </summary>
        public LogicalTable Table { get; set; }

        /// <summary>
        /// Indicate if the index is a cluster index. Default is false.
        /// </summary>
        public bool IsClustered { get; set; }

        private bool isPrimaryKey;
        /// <summary>
        /// Indicate if the index is a primary key index.
        /// </summary>
        public bool IsPrimaryKey
        {
            get { return isPrimaryKey; }
            internal set
            {
                isPrimaryKey = value;
                IsClustered = isPrimaryKey;
            }
        }

        /// <summary>
        /// Indicates if the index is an unique index. Default is true.
        /// </summary>
        public bool IsUnique { get; set; }

        /// <summary>
        /// Gets the index name.
        /// </summary>
        public string Name { get; set; }
    }
}
